package com.example.mywechatstickers;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

/**
 * 显示表情适配器
 * @author n911359
 *
 */
public class StickersAdapter extends BaseAdapter {

    private ArrayList<?> mStickers = null;
    private Context mContext;
    
    public StickersAdapter(Context context, ArrayList<?> arrayList){
        this.mContext = context;
        this.mStickers = arrayList;
    }
    @Override
    public int getCount() {
        return mStickers.size();
    }

    @Override
    public Object getItem(int position) {
        return mStickers.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.view_stickers_item, parent);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        
        holder.ivStickers = (ImageView) convertView.findViewById(R.id.iv_stickers_item);
        
        //加载数据
        holder.ivStickers.setImageResource(R.drawable.ic_launcher);
        
        return convertView;
    }
    
    class ViewHolder{
        ImageView ivStickers;
    }

}
